using Autofac;
using Autofac.Extensions.DependencyInjection;
using NLog;
using NLog.Config;
using NLog.Web;
using Web;

LogManager.Configuration = new XmlLoggingConfiguration("./Configurations/NLog.config");

var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Info("====================== Start program =======================");
try
{
    var builder = WebApplication.CreateBuilder(args);
    var startup = new Startup(builder.Configuration);
    startup.ConfigureServices(builder.Services);
    builder.Host
        //.UseServiceProviderFactory(new AutofacServiceProviderFactory())
        //.ConfigureContainer<ContainerBuilder>(startup.ConfigureContainer)
        .ConfigureLogging((host,builder) =>
        {
            builder.ClearProviders()
                .SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
        }).UseNLog();
    var app = builder.Build();
    startup.Configure(app);
}
catch (Exception ex)
{
    logger.Error(ex, "The program stopped because of exception");
    throw;
}
finally
{
    LogManager.Shutdown();
}
